﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace ElGaleticia
{
	static public class Helper
	{
		static public byte[] StringToBytes(string source)
		{
			BinaryFormatter bf = new BinaryFormatter();
			MemoryStream ms = new MemoryStream();
			bf.Serialize(ms, source);
			ms.Seek(0, 0);
			return ms.ToArray();
		}

		static public string BytesToString(byte[] source)
		{
			BinaryFormatter bf = new BinaryFormatter();
			MemoryStream ms = new MemoryStream();
			ms.Write(source, 0, source.Length);
			ms.Seek(0, 0);
			return (string)bf.Deserialize(ms);
		}

		//static private void dummy() {
		//    byte[] bytes;
		//    //MessageBox.Show("Original bytes Length: " + bytes.Length.ToString());

		//    //MessageBox.Show("Original string Length: " + orig.Length.ToString());

		//    for (int i = 0; i < bytes.Length; ++i) bytes[i] ^= 168; // pseudo encrypt
		//    for (int i = 0; i < bytes.Length; ++i) bytes[i] ^= 168; // pseudo decrypt

		//    BinaryFormatter bfx = new BinaryFormatter();
		//    MemoryStream msx = new MemoryStream();
		//    msx.Write(bytes, 0, bytes.Length);
		//    msx.Seek(0, 0);
		//    string sx = (string)bfx.Deserialize(msx);

		//    //MessageBox.Show("Still intact :" + sx);

		//    //MessageBox.Show("Deserialize string Length(still intact): "
		//    //	+ sx.Length.ToString());

		//    BinaryFormatter bfy = new BinaryFormatter();
		//    MemoryStream msy = new MemoryStream();
		//    bfy.Serialize(msy, sx);
		//    msy.Seek(0, 0);
		//    byte[] bytesy = msy.ToArray();

		//    //MessageBox.Show("Deserialize bytes Length(still intact): "
		//    //   + bytesy.Length.ToString());
		//}
	}
}
